import java.lang.reflect.Constructor;

public class TT {


}


enum TestEnum2 {
    RED,BLACK,GREEN,WHITE;
    public static void main(String[] args) {
        TestEnum2[] testEnum2 = TestEnum2.values();
        for (int i = 0; i < testEnum2.length; i++) {
            System.out.println(testEnum2[i] + " " + testEnum2[i].ordinal());
        }
        System.out.println("=========================");
        System.out.println(TestEnum2.valueOf("GREEN"));
    }

}



enum TestEnum1 {
    RED("red",1),BLACK("black",2),WHITE("white",3),GREEN("green",4);
    private String name;
    private int key;
    /**
     * 1、当枚举对象有参数后，需要提供相应的构造函数
     * 2、枚举的构造函数默认是私有的 这个一定要记住
     * @param name
     * @param key
     */
    private TestEnum1 (String name,int key) {
        this.name = name;
        this.key = key;
    }
    public static TestEnum1 getEnumKey (int key) {

        for (TestEnum1 t: TestEnum1.values()) {
            if(t.key== key) {
                return t;
            }
        }
        return null;
    }



    public static void reflectPrivateConstructor() {
        try {
            Class<?> classStudent = Class.forName("TestEnum");
//注意传入对应的参数,获得对应的构造方法来构造对象,当前枚举类是提供了两个参数分别是String和int。
            Constructor<?> declaredConstructorStudent= classStudent.getDeclaredConstructor(String.class, int.class);
//设置为true后可修改访问权限
            declaredConstructorStudent.setAccessible(true);
            Object objectStudent = declaredConstructorStudent.newInstance("绿色",666);
            TestEnum testEnum = (TestEnum) objectStudent;
            System.out.println("获得枚举的私有构造函数："+testEnum);
        } catch (Exception ex) {
            ex.printStackTrace();
        }



    }


    public static void main(String[] args) {
        reflectPrivateConstructor();
    }
}





enum TestEnum {
    RED,BLACK,GREEN,WHITE;
    public static void main(String[] args) {
//拿到枚举实例BLACK
        TestEnum testEnum = TestEnum.BLACK;
//拿到枚举实例RED
        TestEnum testEnum21 = TestEnum.RED;
        System.out.println(testEnum.compareTo(testEnum21));
        System.out.println(BLACK.compareTo(RED));
        System.out.println(RED.compareTo(BLACK));
    }
}




class Person{
    int age=30;
    String name="person";

    public Person(String name,int age){
        this.name=name;
        this.age=age;
    }
}




class Student extends Person{

    String number;
    int grade;

    public Student(String number,int grade){
        super("human",18);
        this.number=number;
        this.grade=grade;

    }

    public static void main(String[] args) {
        Student student=new Student("202306084131",2023);
        System.out.println("学号与年级"+student.number+student.grade);

    }



}





